<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="员工名称">
              <j-input placeholder="请输入员工名称" v-model="queryParam.name"></j-input>
              <!--              <j-input v-model="queryParam.name" placeholder="请输入审批人"></j-input>-->
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span class="table-page-search-submitButtons" style="float: left; overflow: hidden">
              <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>
              <a-button
                icon="reload"
                style="margin-left: 8px"
                type="primary"
                @click="searchReset"
              >重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />-->
              <!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="plus" type="primary" @click="handleAdd">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('cxm-订单记录信息')">导出</a-button> -->
      <a-upload
        :action="importExcelUrl"
        :headers="tokenHeader"
        :multiple="false"
        :showUploadList="false"
        name="file"
        @change="handleImportExcel"
      >
        <!-- <a-button type="primary" icon="import">导入</a-button> -->
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        bordered
        rowKey="id"
        size="middle"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a-button style="margin-right: 10px;" type="primary" @click="handleEdit(record)">修改</a-button>
          <a-button @click="showModal(record)">作废</a-button>
          <a-modal v-model="visible2" title="作废提示" @ok="getInfo(recordInfo)">
            <p>是否对该条记录进行作废？作废后将无法恢复！</p>
          </a-modal>
        </span>
        <span
          slot="filterDepositAttribute"
          slot-scope="depositAttribute"
        >{{ depositAttribute | filterDepositAttribute(depositAttribute) }}</span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <cxmOrderManager-modal ref="modalForm" @ok="modalFormOk"></cxmOrderManager-modal> -->
    <staff-model ref="modalForm" @ok="modalFormOk"></staff-model>
  </a-card>
</template>

<script>

import StaffModel from './StaffModel.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import moment from 'moment'
import { getAction, postAction, putAction } from '@/api/manage'

export default {
  name: 'Staff',
  mixins: [JeecgListMixin],
  components: {
    StaffModel,
    JInput,
    moment
  },
  data() {
    return {
      nameList: [],
      description: 'sale-审批人设置',
      visible: false,
      visible2: false,
      // 表头
      columns: [
        {
          title: '员工名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '账号名称',
          align: 'center',
          dataIndex: 'sysUserName'
        },
        {
          title: '手机号码',
          align: 'center',
          dataIndex: 'phone'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 250,
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],

      url: {
        list: '/sale/cxmSaleStaffInfo/list',
        delete: '/sale/cxmSaleStaffInfo/delete',
        deleteBatch: '/sale/cxmSaleStaffInfo/deleteBatch'
      },
      recordInfo: {}
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    }
  },
  mounted() {
    console.log(this.dataSource)
    this.getNameList()
  },
  methods: {
    changeStep(value, record) {
      const that = this
      // 触发表单验证
      putAction('/sale/cxmSaleProcessConfig/edit', {
        id: record.id,
        handlerId: record.handlerId,
        step: value.key
      })
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loadData()
        })
    },
    getNameList() {
      getAction('/sale/cxmSaleStaffInfo/queryStaff?name=')
        .then((res) => {
          console.log(res)
          if (res.success) {
            this.nameList = res.result
          } else {
            this.$message.warning(res.message)
          }
        })
    },
    showModal(record) {
      this.visible2 = true
      this.recordInfo = record
    },
    getInfo(recordInfo) {
      /* this.$refs.cxmOrderManagerInfoModal.showDrawer(record) */
      let url = this.url.delete + '?id=' + recordInfo.id
      postAction(url)
        .then((res) => {
          console.log(res)
          if (res.success) {
            this.$message.success(res.message)
            this.$emit('ok')
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
          this.loadData()
          this.visible2 = false
        })
    }
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      switch (depositAttribute) {
        case '1':
          return '可退'
          break
        case '2':
          return '不可退'
          break
        case '3':
          return '有条件可退'
          break
      }
    }
  }
}
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
